package com.ruoyi.shop.popularize.rules.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.common.domain.DtsGrouponRules;
import com.ruoyi.shop.popularize.rules.service.IDtsGrouponRulesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 团购规则Controller
 * 
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/popularize/rules")
public class DtsGrouponRulesController extends BaseController
{
    @Autowired
    private IDtsGrouponRulesService dtsGrouponRulesService;

    /**
     * 查询团购规则列表
     */
    @PreAuthorize("@ss.hasPermi('popularize:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtsGrouponRules dtsGrouponRules)
    {
        startPage();
        List<DtsGrouponRules> list = dtsGrouponRulesService.selectDtsGrouponRulesList(dtsGrouponRules);
        return getDataTable(list);
    }

    /**
     * 导出团购规则列表
     */
    @PreAuthorize("@ss.hasPermi('popularize:rules:export')")
    @Log(title = "团购规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtsGrouponRules dtsGrouponRules)
    {
        List<DtsGrouponRules> list = dtsGrouponRulesService.selectDtsGrouponRulesList(dtsGrouponRules);
        ExcelUtil<DtsGrouponRules> util = new ExcelUtil<DtsGrouponRules>(DtsGrouponRules.class);
        util.exportExcel(response, list, "团购规则数据");
    }

    /**
     * 获取团购规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('popularize:rules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dtsGrouponRulesService.selectDtsGrouponRulesById(id));
    }

    /**
     * 新增团购规则
     */
    @PreAuthorize("@ss.hasPermi('popularize:rules:add')")
    @Log(title = "团购规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtsGrouponRules dtsGrouponRules)
    {
        return toAjax(dtsGrouponRulesService.insertDtsGrouponRules(dtsGrouponRules));
    }

    /**
     * 修改团购规则
     */
    @PreAuthorize("@ss.hasPermi('popularize:rules:edit')")
    @Log(title = "团购规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtsGrouponRules dtsGrouponRules)
    {
        return toAjax(dtsGrouponRulesService.updateDtsGrouponRules(dtsGrouponRules));
    }

    /**
     * 删除团购规则
     */
    @PreAuthorize("@ss.hasPermi('popularize:rules:remove')")
    @Log(title = "团购规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dtsGrouponRulesService.deleteDtsGrouponRulesByIds(ids));
    }
}
